1 //DEVELOPED BY G. Rohit
2
3 //C++ PROJECT
4
5 //START OF THE PROGRAM FOR HOTEL MANAGEMENT

6
7 #include<iostream>
8 #include<conio.h>
9 #include<fstream>
10 #include<stdio.h>
11 #include<stdlib.h>
12 #include<dos.h>

13
14 using
namespace std;
15
16 //START OF CLASS

17
18
19
20 class
hotel
21 {

22
23 int
room_no;
24 char
name[30];
25 char
address[50];
26 char
phone[10];
27
28 public
:
29
30 void
main_menu(); //to dispay the main menu
31 void
add(); //to book a room
32 void
display(); //to display the customer record
33 void
rooms(); //to display alloted rooms
34 void
edit(); //to edit the customer record
35 int
check(int); //to check room status
36 void
modify(int); //to modify the record
37 void
delete_rec(int); //to delete the record
38 void
bill(int); //for the bill of a record
39      };
40     
//END OF CLASS
41
42
43
44 //FOR DISPLAYING MAIN MENU

45
46
47
48 void
hotel::main_menu()
49 {

50
51 int
choice;
52 while
(choice!=5)
53 {
54
55   system(
"cls");
56 cout<<
"\n\t\t\t\t*************************";
57 cout<<
"\n\t\t\t\t SIMPLE HOTEL MANAGEMENT ";
58 cout<<
"\n\t\t\t\t * MAIN MENU *";
59 cout<<
"\n\t\t\t\t*************************";
60 cout<<
"\n\n\n\t\t\t1.Book A Room";
61 cout<<
"\n\t\t\t2.Customer Records";
62 cout<<
"\n\t\t\t3.Rooms Allotted";
63 cout<<
"\n\t\t\t4.Edit Record";
64 cout<<
"\n\t\t\t5.Exit";
65 cout<<
"\n\n\t\t\tEnter Your Choice: ";
66 cin>>choice;

67
68 switch
(choice)
69 {

70
71 case
1: add();
72 break
;
73
74 case
2: display();
75 break
;
76
77 case
3: rooms();
78 break
;
79
80 case
4: edit();
81 break
;
82
83 case
5: break;
84
85 default
:
86 {
87
88 cout<<
"\n\n\t\t\tWrong choice.....!!!";
89 cout<<
"\n\t\t\tPress any key to continue....!!";
90 getch();
91
92 }
93
94 }
95
96 }
97
98 }

99
100
101 //END OF MENU FUNCTION
102
103
104 //FUNCTION FOR BOOKING OF ROOM

105
106
107 void
hotel::add()
108 {
109
110   system(
"cls");
111 int
r,flag;
112 ofstream fout(
"Record.dat",ios::app);
113
114 cout<<
"\n Enter Customer Detalis";
115 cout<<
"\n ----------------------";
116 cout<<
"\n\n Room no: ";
117 cout<<
"\n Total no. of Rooms - 50";
118 cout<<
"\n Ordinary Rooms from 1 - 30";
119 cout<<
"\n Luxuary Rooms from 31 - 45";
120 cout<<
"\n Royal Rooms from 46 - 50";
121 cout <<
"\n Enter The Room no. you want to stay in :- "<<endl;
122 cin>>r;
123
124 flag=check(r);

125
126 if
(flag)
127 cout<<
"\n Sorry..!!!Room is already booked";
128
129 else

130 {
131
132 room_no=r;
133 cout<<
" Name: ";
134 cin>>name;
135 cout<<
" Address: ";
136 cin>>address;
137 cout<<
" Phone No: ";
138 cin>>phone;
139
140 fout.write((
char*)this,sizeof(hotel));
141 cout<<
"\n Room is booked...!!!";
142
143 }
144
145 cout<<
"\n Press any key to continue.....!!";
146
147 getch();
148 fout.close();
149
150 }

151
152
153 //END OF BOOKING FUNCTION
154
155
156 //FUNCTION FOR DISPLAYING A PURTICULAR CUSTOMER`S RECORD

157
158
159
160
161
162 void
hotel::display()
163 {
164
165   system(
"cls");
166
167 ifstream fin(
"Record.dat",ios::in);
168 int
r,flag;
169
170 cout<<
"\n Enter room no. for a particular customer`s details :- "<<endl;
171 cin>>r;

172
173 while
(!fin.eof())
174 {
175
176 fin.read((
char*)this,sizeof(hotel));
177 if
(room_no==r)
178 {
179
180   system(
"cls");
181 cout<<
"\n Cusromer Details";
182 cout<<
"\n ----------------";
183 cout<<
"\n\n Room no: "<<room_no;
184 cout<<
"\n Name: "<<name;
185 cout<<
"\n Address: "<<address;
186 cout<<
"\n Phone no: "<<phone;
187 flag=
1;
188 break
;
189
190 }
191
192 }

193
194 if
(flag==0)
195 cout<<
"\n Sorry Room no. not found or vacant....!!";
196 cout<<
"\n\n Press any key to continue....!!";
197
198 getch();
199 fin.close();
200 }

201
202
203 //END OF DISPLAY FUNCTION
204
205 //FUNCTION TO DISPLAY ALL ROOMS OCCUPIED

206
207
208 void
hotel::rooms()
209 {
210
211   system(
"cls");
212
213 ifstream fin(
"Record.dat",ios::in);
214 cout<<
"\n\t\t\t List Of Rooms Allotted";
215 cout<<
"\n\t\t\t ----------------------";
216 cout<<
"\n\n Room No.\tName\t\tAddress\t\t\t\tPhone No.\n";
217
218 while
(!fin.eof())
219 {
220
221 fin.read((
char*)this,sizeof(hotel));
222 cout<<
"\n\n "<<room_no<<"\t\t"<<name;
223 cout<<
"\t\t"<<address<<"\t\t"<<phone;
224
225 }
226
227 cout<<
"\n\n\n\t\t\tPress any key to continue.....!!";
228 getch();
229 fin.close();
230
231 }

232
233
234 //FUNCTION FOR EDITING RECORDS AND FOR BILL

235
236
237 void
hotel::edit()
238 {
239
240   system(
"cls");
241
242 int
choice,r;
243 cout<<
"\n EDIT MENU";
244 cout<<
"\n ---------";
245 cout<<
"\n\n 1.Modify Customer Record";
246 cout<<
"\n 2.Delete Customer Record";
247 cout<<
"\n 3. Bill Of Customer";
248 cout<<
"\n Enter your choice: ";
249
250 cin>>choice;
251   system(
"cls");
252
253 cout<<
"\n Enter room no: " ;
254 cin>>r;

255
256 switch
(choice)
257 {

258
259 case
1: modify(r);
260 break
;
261
262 case
2: delete_rec(r);
263 break
;
264
265 case
3: bill(r);
266 break
;
267
268 default
: cout<<"\n Wrong Choice.....!!";
269
270 }
271 cout<<
"\n Press any key to continue....!!!";
272
273 getch();
274 }

275
276
277 int
hotel::check(int r)
278 {

279
280 int
flag=0;
281
282 ifstream fin(
"Record.dat",ios::in);
283
284 while
(!fin.eof())
285 {
286
287 fin.read((
char*)this,sizeof(hotel));
288 if
(room_no==r)
289 {
290
291 flag=
1;
292 break
;
293
294 }
295
296 }
297
298 fin.close();

299 return
(flag);
300
301 }

302
303
304 //FUNCTION TO MODIFY CUSTOMERS RECORD

305
306
307 void
hotel::modify(int r)
308 {

309
310 long
pos,flag=0;
311
312 fstream file(
"Record.dat",ios::in|ios::out|ios::binary);
313
314 while
(!file.eof())
315 {
316
317 pos=file.tellg();
318 file.read((
char*)this,sizeof(hotel));
319
320 if
(room_no==r)
321 {
322
323 cout<<
"\n Enter New Details";
324 cout<<
"\n -----------------";
325 cout<<
"\n Name: ";
326 cin>>name;
327 cout<<
" Address: ";
328 cin>>address;
329 cout<<
" Phone no: ";
330 cin>>phone;
331 file.seekg(pos);
332 file.write((
char*)this,sizeof(hotel));
333 cout<<
"\n Record is modified....!!";
334 flag=
1;
335 break
;
336
337 }
338
339 }

340
341 if
(flag==0)
342 cout<<
"\n Sorry Room no. not found or vacant...!!";
343 file.close();
344
345 }

346
347
348 //END OF MODIFY FUNCTION
349
350
351 //FUNCTION FOR DELETING RECORD

352
353
354 void
hotel::delete_rec(int r)
355 {

356
357 int
flag=0;
358 char
ch;
359 ifstream fin(
"Record.dat",ios::in);
360 ofstream fout(
"temp.dat",ios::out);
361
362 while
(!fin.eof())
363 {
364
365 fin.read((
char*)this,sizeof(hotel));
366 if
(room_no==r)
367
368 {
369
370 cout<<
"\n Name: "<<name;
371 cout<<
"\n Address: "<<address;
372 cout<<
"\n Pone No: "<<phone;
373 cout<<
"\n\n Do you want to delete this record(y/n): ";
374 cin>>ch;

375
376 if
(ch=='n')
377 fout.write((
char*)this,sizeof(hotel));
378 flag=
1;
379
380 }

381
382 else

383 fout.write((
char*)this,sizeof(hotel));
384
385 }
386
387 fin.close();
388 fout.close();

389
390 if
(flag==0)
391 cout<<
"\n Sorry room no. not found or vacant...!!";
392
393 else

394 {

395
396 remove
("Record.dat");
397 rename(
"temp.dat","Record.dat");
398
399 }
400
401 }

402
403
404 //END OF DELETE FUNCTION
405
406
407 //FUNCTION FOR CUSTOMER`S BILL

408
409 void
hotel::bill(int r)
410 {
411
412 hotel h1;
413 ifstream f1;
414  f1.open(
"record.dat",ios::in|ios::binary);
415
416 if
(!f1)
417  cout<<
"cannot open";
418
419  
else
420  {
421
422   f1.read((
char*)&h1,sizeof (hotel));
423   
while(f1)
424
425   {
426
427   f1.read((
char*)&h1,sizeof(hotel));
428
429   }
430
431   
if (h1.room_no == r)
432   {
433
434   
if(h1.room_no>=1&&h1.room_no<=30)
435   cout<<
"your bill = 2000";
436
437   
else if (h1.room_no>=35&&h1.room_no<=45)
438   cout<<
"your bill = 5000" ;
439
440   
else
441   cout<<
"your bill = 7000";
442
443   }
444
445   
else
446   { cout<<
"room no. not found";}
447
448   }
449
450   f1.close();
451   getch();
452
453 }

454
455 //END OF BILLING FUNCTION
456
457 //START OF MAIN PROGARM

458
459
460 int
main()
461 {
462
463 hotel h;
464
465   system(
"cls");
466
467 cout<<
"\n\t\t\t****************************";
468 cout<<
"\n\t\t\t* HOTEL MANAGEMENT PROJECT *";
469 cout<<
"\n\t\t\t****************************";
470 cout<<
"\n\n\t\tDeveloped By:";
471 cout<<
"\t G. Rohit";
472 cout<<
"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
473
474 getch();
475
476 h.main_menu();

477 return
0;
478 }

479
480 //END OF MAIN PROGRAM


Gõ tìm kiếm nhanh...